package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.mapper.UserMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by 13925 on 2018/10/28.
 */

/**
 * 后台用户服务实现层
 */
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    UserMapper userMapper;

    public User getUserByEmailAndPassword(String email, String password) {
        return userMapper.selectUserByEmailAndPassword(email, password);
    }

    @Override
    public void save(User user) {
        userMapper.insert(user);
    }

    /**
     * mybatis分页插件配置
     *
     * @param qo
     * @return
     */
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<User> list = userMapper.selectForList(qo);
        //分页数据封装成对象 等价于Pageresult
        return new PageInfo(list);
    }

    public void update(User user) {
        userMapper.updateByPrimaryKey(user);
    }
}
